package com.ai3d.rfid.common.proxy

import android.app.Application
import com.ai3d.rfid.BuildConfig
import com.ai3d.rfid.common.log.Logcat
import com.tencent.mmkv.MMKV

/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2022/10/21 11:35
 * @Description : SP数据存储
 */
object MMKVProxy {
    private const val MMKV_STORAGE_PATH_KEY = "/mmkv"
    const val KEY_PRIVACY_AGREE = "key_privacy_agree"

    //登录
    const val KEY_TOKEN = "key_token"
    const val KEY_USER_ID = "key_user_id"
    const val KEY_LAST_LOGIN_TIME = "key_last_Login_Time"
    const val USER_NAME = "user_name"
    const val USER_PWD = "user_pwd"
    //设置
    const val KEY_SETTINGS_LANGUAGE_MAIN = "settings_language_main_key"
    const val KEY_SETTINGS_LANGUAGE_ASSIST = "settings_language_assist_key"
    const val KEY_SETTINGS_SKIN_MODE = "key_settings_skin_mode"
    const val KEY_SETTINGS_SKIN_THEME = "key_settings_skin_theme"
    const val KEY_SETTINGS_FONT = "key_settings_font"

    //static.zip
    const val KEY_NEED_DOWNLOAD_RANGE = "key_need_download_range"
    const val KEY_NEED_NEED_UNZIP = "key_need_unzip"
    const val KEY_STATIC_ZIP_FILE_LENGTH = "key_static_zip_file_length"
    const val KEY_DOWNLOAD_FILE_FINISH_LENGTH = "key_download_file_finish_length"
    const val KEY_NEED_DOWNLOAD = "key_need_download"

    //first enter loading
    const val KEY_FIRST_H5_LOADING = "key_first_h5_loading"
    const val COMPANY_PK_ID = "company_pk_id"
    const val IS_OPEN_BUZZER = "is_open_buzzer"
    const val PROTOCOL_TYPE = "protocol_type"//1 6c 2 6b 3 gb

    const val READ_TYPE = "read_type"//0单次读取 1多次读取

    //game reset
    const val KEY_OC_GAME_RESET = "key_oc_game_reset"
    const val KEY_DF_GAME_RESET = "key_df_game_reset"
    const val KEY_UOT_GAME_RESET = "key_uot_game_reset"

    //游戏进度
    const val GAME_PROGRESS = "game_progress"
    const val LAST_THEME = "last_theme"//上次取的主题

    const val UOT = "uot"
    const val UOT_GAMESESSIONID = "uot_gamesessionid"
    const val UOT_LEVELSESSIONID = "uot_levelsessionid"//这个需要拼接hard作为key 因为每一个hard是不同值
    const val UOT_SESSIONID = "uot_sessionid" //每一个level是不同值
    const val UOT_IS_SHOW_FIRST_SECOND_LEVEL = "uot_is_show_first_second_level"//是否已经显示引导关
    const val UOT_LIST = "uot_list"//主题数据
    const val OC = "oc"
    const val OC_GAMESESSIONID = "oc_gamesessionid"
    const val OC_LEVELSESSIONID = "oc_levelsessionid"//这个需要拼接hard作为key 因为每一个hard是不同值
    const val OC_SESSIONID = "oc_sessionid"
    const val OC_IS_SHOW_FIRST_SECOND_LEVEL = "oc_is_show_first_second_level"//是否已经显示引导关
    const val OC_LIST = "oc_list"//主题数据

    //vf游戏
    const val VF = "vf"
    const val VF_GAMESESSIONID = "vf_gamesessionid"
    const val VF_LEVELSESSIONID = "vf_levelsessionid"//这个需要拼接hard作为key 因为每一个hard是不同值
    const val VF_SESSIONID = "vf_sessionid"

    //事件上报
    const val KEY_EVENT_UPLOAD_TIME = "key_event_upload_time"

    const val MACHINEID = "machineId"//雪花唯一id

    fun initMMKV(application: Application) {
        MMKV.initialize(application.filesDir.absolutePath + MMKV_STORAGE_PATH_KEY)
    }

    fun getString(key: String, defValue: String): String {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeString(key, defValue)
    }

    fun getString(key: String): String? {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeString(key)
    }

    fun setString(key: String, defValue: String) {
        MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).encode(key, defValue)
    }

    fun getLong(key: String): Long {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeLong(key)
    }

    fun getLong(key: String, defValue: Long): Long {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeLong(key, defValue)
    }

    fun setLong(key: String?, defValue: Long) {
        MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).encode(key, defValue)
    }

    fun setInt(key: String, defValue: Int) {
        MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).encode(key, defValue)
    }

    fun getInt(key: String, defValue: Int): Int {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeInt(key, defValue)
    }

    fun getBoolean(key: String, defValue: Boolean): Boolean {
        return MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).decodeBool(key, defValue)
    }

    fun setBoolean(key: String, defaultValue: Boolean) {
        MMKV.mmkvWithID(BuildConfig.APPLICATION_ID).encode(key, defaultValue)
    }

    fun logoutClear() {
        setLong(KEY_LAST_LOGIN_TIME, 0)
        setString(KEY_TOKEN, "")
        setString(KEY_USER_ID, "")
        setInt(MACHINEID,0)
        Logcat.d("退出", "11111111111111111  logoutClear  ${getString(MMKVProxy.KEY_TOKEN)}")
    }
}